﻿<%@ Page Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="true" CodeBehind="Categories.aspx.cs" Inherits="Admin.Admin.Categories" Title="Untitled Page" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        function confirmAction()
         {
            if(confirm('Bạn có chắc chắn muốn xóa???'))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    </script>
<script type="text/javascript">
    function SelectAll(CheckBox)
    {
        TotalChkBx = parseInt('<%= this.GridView1.Rows.Count %>');    
        var TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
        var TargetChildControl = "chkSelect";   
        var Inputs = TargetBaseControl.getElementsByTagName("input");
        for(var iCount = 0; iCount < Inputs.length; ++iCount)
        {                
            if(Inputs[iCount].type == 'checkbox' && Inputs[iCount].id.indexOf(TargetChildControl,0) >= 0)
                Inputs[iCount].checked = CheckBox.checked;   
        }

    }
    
    function SelectDeSelectHeader(CheckBox)
    {        
        TotalChkBx = parseInt('<%= this.GridView1.Rows.Count %>');    
        var TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
        var TargetChildControl = "chkSelect";   
        var TargetHeaderControl = "chkSelectAll";   
        var Inputs = TargetBaseControl.getElementsByTagName("input");
        var flag = false;
        var HeaderCheckBox;
        for(var iCount = 0; iCount < Inputs.length ; ++iCount)
        {    
            if(Inputs[iCount].type == 'checkbox' && Inputs[iCount].id.indexOf(TargetHeaderControl,0) >= 0)            
                HeaderCheckBox = Inputs[iCount];            
            if(Inputs[iCount] != CheckBox && Inputs[iCount].type == 'checkbox' && Inputs[iCount].id.indexOf(TargetChildControl,0) >= 0 && Inputs[iCount].id.indexOf(TargetHeaderControl,0) == -1)
            {            
                if(CheckBox.checked)
                {                    
                    if(!Inputs[iCount].checked)                    
                    {                    
                        flag = false;
                        HeaderCheckBox.checked = false;                       
                        return;
                    }
                    else
                        flag = true;                    
                }
                else if(!CheckBox.checked)                
                    HeaderCheckBox.checked = false;                                                       
            }            
        }                      
        if(flag)        
            HeaderCheckBox.checked = CheckBox.checked        
    }
</script>


   <asp:ScriptManager ID="ScriptManager1" runat="server">
                    </asp:ScriptManager>
 <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
     <ContentTemplate>
           <asp:Panel ID="PanelDasboard" runat="server"  Visible="true">
            <div class="dashboard">
                <h2 class="ico_mug">
                    <asp:Label ID="lbcategory" runat="server" Text="Danh sách danh mục"></asp:Label>
                </h2>

                <div style="width:100%;">
                    <p style="margin-right:10px;float:left;">
                        <asp:LinkButton ID="btnthemmoi" runat="server" Font-Bold="True" ForeColor="Blue" 
                            onclick="btnthemmoi_Click" Visible="False">Thêm mới</asp:LinkButton></p>
                    <p><asp:LinkButton ID="btnxoa" runat="server" 
                            OnClientClick="javascript:return confirmAction();" Font-Bold="True" 
                            ForeColor="Blue" onclick="btnxoa_Click" Visible="False">Xoá mục được chọn</asp:LinkButton></p>
                </div>

                <div>
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                        CellPadding="4" DataKeyNames="CategoryID"
                        Width="100%" 
                        onselectedindexchanged="GridView1_SelectedIndexChanged" AllowPaging="True" 

                        ForeColor="#333333" GridLines="None" 
                        onrowdatabound="GridView1_RowDataBound" >
                        <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
                        <RowStyle BackColor="#EFF3FB" />
                        <Columns>
                            <asp:CommandField ButtonType="Image" SelectImageUrl="~/Admin/img/edit.png" 
                                ShowSelectButton="True" >
                                <ItemStyle Width="50px" />
                            </asp:CommandField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="chkSelect" runat="server" />
                                </ItemTemplate>
                                <HeaderTemplate>
                                 <asp:CheckBox ID="chkSelectAll" runat="server" onclick="SelectAll(this);" />                                
                                </HeaderTemplate>
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                            <asp:BoundField DataField="CategoryID" HeaderText="Mã nhà đất" ReadOnly="True" 
                                SortExpression="CategoryID" InsertVisible="False" >
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle Width="170px" HorizontalAlign="Center" />
                            </asp:BoundField>
                            <asp:BoundField DataField="CategoryName" HeaderText="Tên nhà đất" 
                                SortExpression="CategoryName" >
                                <HeaderStyle HorizontalAlign="Left" />
                                <ItemStyle Width="200px" />
                            </asp:BoundField>
                            <asp:TemplateField HeaderText="Kích hoạt">
                                <ItemTemplate>
                                    <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Eval("IsActive") %>' 
                                        Enabled="False" />
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <EditRowStyle BackColor="#2461BF" />
                        <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>
                    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
                        SelectMethod="GetCategoryBOList" TypeName="HousingInfo.Library.CategoryBOList">
                    </asp:ObjectDataSource>
                    <asp:Label ID="messagedelete" runat="server" Font-Bold="True" Font-Size="Small" 
                        ForeColor="Red"></asp:Label>
                    <br />
                </div>
            </div>
       </asp:Panel>
    <asp:Panel ID="PanelActions" runat="server"  Visible="false">
    <div class="dashboard">
        <h2 class="ico_mug">
            <asp:Label ID="lbHeaderActions" runat="server" Text="Loại nhà đất"></asp:Label>
        </h2>
       
       
        <div>
            <table style="width: 100%">
                <tr>
                    <td style="width: 132px">
                        &nbsp;</td>
                    <td style="width: 19px">
                        &nbsp;</td>
                    <td>
                        <asp:Label ID="message" runat="server" Font-Bold="True" Font-Size="Small" 
                            ForeColor="Red"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td style="width: 132px; text-align: right;">

                        <asp:Label ID="LabelCategoryID" runat="server" Text="Mã danh mục :"></asp:Label>
                    </td>
                    <td style="width: 19px">
                        &nbsp;</td>
                    <td>
                        <asp:TextBox ID="txtCategoryID" runat="server" ReadOnly="True" Width="172px" 
                            Enabled="False"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="width: 132px; text-align: right;">

                        <asp:Label ID="lbcategoryname" runat="server" Text="Tên danh mục :"></asp:Label>
                    </td>
                    <td style="width: 19px">
                        &nbsp;</td>
                    <td>
                        <asp:TextBox ID="txtcategoryname" runat="server" Width="172px" MaxLength="50"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                            ControlToValidate="txtcategoryname" ErrorMessage="?"></asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" 
                            ControlToValidate="txtcategoryname" ErrorMessage="Độ dài tối thiểu &gt; 1 và tối đa là 50" 
                            ValidationExpression="^([\S\s]{2,50})$"></asp:RegularExpressionValidator>
                    </td>
                </tr>
                
                <tr>
                    <td style="width: 132px; text-align: right;">
                        <asp:Label ID="Label10" runat="server" Text="Kích hoạt :"></asp:Label>
                    </td>
                    <td style="width: 19px">
                        &nbsp;</td>
                    <td>
                        <asp:CheckBox ID="isActive" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 132px">
                        &nbsp;</td>
                    <td style="width: 19px">
                        &nbsp;</td>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td style="width: 132px">
                        &nbsp;</td>
                    <td style="width: 19px">
                        &nbsp;</td>
                    <td>
                        <asp:Button ID="btnUpdate" runat="server" Text="Cập nhật" 

                            onclick="btnUpdate_Click" />                    
                        <asp:Button ID="btnAdd" runat="server" onclick="btnAdd_Click" Text="Thêm" />

                        <asp:Button ID="btndong" runat="server" Text="Đóng" onclick="btndong_Click" 
                            CausesValidation="False" />
                    </td>
                </tr>
            </table>
        </div>
    </div>

     </asp:Panel>    

</ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
